#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int topo(vector<vector<int>> &gh, vector<int> &indgree, int n)
{
        vector<int> weight(n + 1, 0);
        queue<int> q;
        for(int i = 1; i <= n; i++){
                if(indgree[i] == 0){
                        q.push(i);
                }
        }

        int ans = 0, mid = n / 2;
        while(!q.empty()){
                int u = q.front();
                q.pop();
                if(weight[u] > mid ){
                        ans++;
                }
                for(auto v : gh[u]){
                        weight[v] += weight[u] + 1;
                        if(--indgree[v] == 0){
                                q.push(v);
                        }
                }
        }
        
        return ans;
}

int main()
{
	int n, m;
	cin >> n >> m;
        vector<vector<int>> gh(n + 1), rgh(n + 1);
	vector<int> weight(n + 1, 0), indgree(n + 1, 0), rindgree(n + 1, 0);

        for(int i = 0; i < m; i++){
                int u, v;
                cin >> u >> v;
                gh[u].push_back(v);
                indgree[v]++;

                rgh[v].push_back(u);
                rindgree[u]++;
        }

        int ans = topo(gh, indgree, n);
        ans += topo(rgh, rindgree, n);
        cout<<ans<<endl;
	return 0;
}